/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package guiexample;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.util.Timer;
import java.util.TimerTask;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
/**
 *
 * @author Sean
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here

        BackgroundPanel b = new BackgroundPanel();
        TankController controller = new TankController();
        Tank tank = new Tank();
        final TankView view = new TankView(tank, controller);
        controller.setTank(tank);
        controller.setView(view);

        Timer timer = new Timer();
        TimerTask task = new TimerTask() {
            @Override
            public void run() {
                view.repaint();
            }
        };

        int fps = 60;
        timer.scheduleAtFixedRate(task, 0, 1000/fps);
        view.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        view.setSize(new Dimension(1000, 500));
        view.setTitle("GUI Example");
        view.setVisible(true);

    }
}
class BackgroundPanel extends JPanel
{
  Image image;
  public BackgroundPanel()
  {
    try
    {
      image = javax.imageio.ImageIO.read(new java.net.URL(getClass().getResource("./background.png"), "./background.png"));
    }
    catch (Exception e) { /*handled in paintComponent()*/ }
  }
  //JPanel panel = new BackgroundPanel();
  @Override
  public void paintComponent(Graphics g)
  {

    Graphics2D g2 = (Graphics2D) g;
    if (image != null)
      g2.drawImage(image, 0,0,this.getWidth(),this.getHeight(),this);
  }
}